package com.tutorialspoint.DI;

import com.tutorialspoint.base.MyBase;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class DIMainApp extends MyBase {
	public static void main(String[] args) {
		
		// dependency injection by constructor
		ApplicationContext context_constructor = 
				new ClassPathXmlApplicationContext("Beans_DIByConstructor.xml");
		TextEditor te = (TextEditor) context_constructor.getBean("textEditor");
		te.spellCheck();
		
		// dependency injection by setter
		ApplicationContext context_setter = 
				new ClassPathXmlApplicationContext("Beans_DIBySetter.xml");
		TextEditor te1 = (TextEditor) context_setter.getBean("textEditor");
		te1.spellCheck();
		
		// dependency injection by setter
		ApplicationContext context_innerBean = 
				new ClassPathXmlApplicationContext("Beans_DIByInnerBean.xml");
		TextEditor te2 = (TextEditor) context_setter.getBean("textEditor");
		te2.spellCheck();
		
		// DI collection
		ApplicationContext context_cln = 
				new ClassPathXmlApplicationContext("Beans_DICollection.xml");
		JavaCollection jc = (JavaCollection) context_cln.getBean("javaCollection");
		jc.getAddressList();
		jc.getAddressMap();
		jc.getAddressSet();
		jc.getAddressProp();
		
		// close context
		DIMainApp.closeContext(context_constructor);
		DIMainApp.closeContext(context_setter);
		DIMainApp.closeContext(context_innerBean);
		DIMainApp.closeContext(context_cln);
	}
}
